//
//  GroupOrderListCtr.swift
//  eemall
//
//  Created by zhuxietong on 2018/12/28.
//  Copyright © 2018 tianrun. All rights reserved.
//

import UIKit
import Foundation
import soapp
import AsyncDisplayKit
import Eelay

open class GroupOrderListCtr:ASCollectionContainer{
    
    open override func viewDidLoad() {
        self.page_load_section = "section0"
        self.content = ASTermsContainer.list(
            net: JoTask()._surl(.我的团列表).post,
            node: "list",
            emptyMsg: "没有相关内容".loc,
            params: nil,
            cellType: Cell.self,
            detailType:GroupInfoCtr.self,
            test: false
        )
        
        super.viewDidLoad()
        self.title = "我的团购".loc
        collectionNode.backgroundColor = UIColor.table_bg_color
        if JoUser.loginUser() == nil{
            
        }
        else{
            reload_page()
        }
    }
    
    open override func loadOnePage(list: [Any]) -> [Any] {
        return super.loadOnePage(list: list)
    }
}

extension GroupOrderListCtr{
    
    class Cell: JoCellNode {
        let imgV = JoImageNode()
        let nameL = ASTextNode2()
        let optionL = ASTextNode2()
        let priceL = ASTextNode2()
        let statusL = ASTextNode2()
    
        let line = ASDisplayNode()
        let bt1 = ASButtonNode()
        let bt2 = ASButtonNode()
        
        
        let markL = EeMarkNode()

        override func cellTouch() {
            
        }
        
        override func addLayoutRules() {
            markL.msgType = GMsgType.groups.msg
        }
        override func mo_model_reload() {
            
            imgV.img_url = mo.model["thumb",""]
            backgroundColor = ._cellBackground
            line.backgroundColor = UIColor._separator
            separatorTopHeight = 8
            separatorTopColor = UIColor._tableBackground
            
            nameL.attributedText = mo.model["title",""].ui.font14.color(color:._foreground).astring
            statusL.attributedText = "组团中".loc.ui.font12.cl_888.astring
//
//            priceL.attributedText = "团购价:".ui.font12.cl_444.astring + "¥ ".ui.font11.color(hex: "#5FB187").astring + mo.model[float:"amount",0].price_display.ui.font14.color(hex: AppTheme.main_hex).astring
            
            priceL.attributedText = "\("团购价".loc):".ui.font12.color(color: ._foreground).astring + "¥ ".ui.font11.color(hex: "#5FB187").astring + _Tool.price1(mo.model["groupsprice",""])
            
            bt1.ui.padding(insets: [6,12]).font(size: 13).ncolor(hex: "#999").ntitle(title: "团购详情".loc).set(radius: 3, width: 1, color: UIColor(shex: "#999"))
            bt2.ui.padding(insets: [6,12]).font(size: 13).ncolor(hex: "#999").ntitle(title: "订单详情".loc).set(radius: 3, width: 1, color: UIColor(shex: "#999"))
            
            optionL.attributedText = mo.model["option_name",""].ui.font12.cl_666.astring
            bt2.addTarget(self, action: #selector(seeOrder), forControlEvents: .touchUpInside)
            markL.markID = mo.model["teamid",""]
        }
        
        @objc func seeOrder() {
            let ctr = GroupOrderDetailCtr()
            ctr.mo.model = mo.model
            mo.controller?.navigationController?.pushViewController(ctr, animated: true)
        }
        
        
        override func specGetter() -> _Spec {
            let spec = _Spec.stack(["h|10",&-.stretch], childs: [
                imgV[80,"80"],
                _Spec.stack(["v|8",_grow(1),_shrink(1),&-.stretch], childs: [
                    .stack(["h|10",&-.center,_justfy(.space_between)], childs: [
                        nameL[_grow(1),_shrink(1)],
                        markL.Spec
                        ]),
                    optionL.Spec,
                    priceL.Spec
                ])
            ])
            
            
            return _Spec.stack(["v",&-.stretch,[10,AppTheme.edge]], childs: [
                spec,
                _Spec.inset([], [10,0], child: line["\(TP.separatorHeight)"]),
                .stack(["h",&-.center,_justfy(.space_between)], childs: [
                    statusL.Spec,
                    .stack(["h|12",&-.center], childs: [
                        bt1.Spec,bt2.Spec
                        ])
                    ])
                ])
        }
    }
}
